<template>
  <div class="home-recommond">
    <h2>电台推荐</h2>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="(item, index) in listData" :key="index">
          <!-- v-for 类似增强for循环。item为声明的对象，index即当前项的索引，Key是主要为了标识。 index和key是可选的
          listdata为需要遍历的数组。-->
          <div class="cover">
            <van-image :src="item.picUrl" radius="1rem" />
            <span :title="item.copywriter">{{ item.copywriter }}</span>
          </div>
          <span :title="item.name">{{ item.name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getListData();
  },
  //获取到热门歌手的数据
  methods: {
    //列表获取照片
    getListData() {
      this.$request("get", "/personalized/djprogram").then((res) => {
        console.log("推荐电台数据", res);
        if (res.code == 200) {
          this.listData = res.result;
        }
        //异步数据的一些处理,调用封装的横向滚动方法
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        );
      });
    },
  },
};
</script>
<style>
.cover > span {
  padding: 0 0 0 1rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  position: absolute;
  right: 0;
  width: 5rem;
  bottom: 0.3rem;
  color: white;
  font-size: 14px;
  border-radius: 1rem;
  display: inline-block;
  background: rgba(0, 0, 0, 0.4);
}
.cover {
  position: relative;
}
.wrapper {
  width: 100%;
  overflow: hidden;
}
ul.content {
  width: calc(12 * 10rem);
}
ul.content li {
  display: inline-block;
  width: 10rem;
  vertical-align: top;
}
ul.content li * {
  margin: 0.1rem;
}
ul.content li > span {
  width: 9rem;
  font-size: 0.6rem;
  color: #54493b;
  margin: 0 auto;
  height: 2rem;
  vertical-align: middle;
  display: table-cell;
}
</style>